package Time;

import java.util.Calendar;
import java.util.GregorianCalendar;

public class Time {
    
    //returns HR:MIN:SEC format of the time
    public static String getHrMinSec(){
                GregorianCalendar cal = new GregorianCalendar();
                Integer sec = cal.get(Calendar.SECOND);
                Integer min = cal.get(Calendar.MINUTE);
                String minute = min.toString();
                String second = sec.toString();
                if(sec.toString().length()==1)
                    second = "0" + sec;
                if(min.toString().length()==1)
                    minute = "0" + min;
                return cal.get(Calendar.HOUR)+":"+minute+":"+second;

    }
    
    public static int getDifInMins(String start, String end){
        String[] s = start.split(":");
        String[] e = end.split(":");
        int hourS,hourE,minS,minE;
        hourS = Integer.parseInt(s[0]);
        hourE = Integer.parseInt(e[0]);
        minS = Integer.parseInt(s[1]);
        minE = Integer.parseInt(e[1]);
        return (60-minS)+((hourE-(hourS+1))*60)+minE;
    }
    
    public static String addMinutes(String time,int min){
        String[] t = time.split(":");
        int minutes = Integer.parseInt(t[1])+min;
        if(minutes>=60){
            int newMin = minutes-60;
            int hour = Integer.parseInt(t[0]) +1;
            return hour+":"+newMin+":"+t[2];
        }
        return t[0]+":"+minutes+":"+t[2];
        
    }
    
}
